package com.example.imtao;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;

import com.example.imtao.fragment.FindFragment;
import com.example.imtao.fragment.MainFragment;
import com.example.imtao.fragment.MeFragment;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{

    protected LinearLayout mMenuMain;
    protected LinearLayout mMenuFind;
    protected LinearLayout mMenuMe;
    protected MainFragment mMainFragment = new MainFragment();
    protected FindFragment mFindFragment = new FindFragment();
    protected MeFragment mMeFragment=new MeFragment();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initView();
        this.getSupportFragmentManager()
                .beginTransaction()
                .add(R.id.container_content,mMainFragment)
                .add(R.id.container_content,mFindFragment)
                    .hide(mFindFragment)
                    .add(R.id.container_content,mMeFragment)
                    .hide(mMeFragment)


        .commit();


    }

    public void initView(){
        mMenuMain=(LinearLayout)this.findViewById((R.id.menu_main));
        mMenuFind=(LinearLayout)this.findViewById((R.id.menu_find));
        mMenuMe=(LinearLayout)this.findViewById((R.id.menu_me));
        mMenuMain.setOnClickListener(this);
        mMenuFind.setOnClickListener(this);
        mMenuMe.setOnClickListener(this);



    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case  R.id.menu_main:
                this.getSupportFragmentManager()
                        .beginTransaction()
                        .show(mMainFragment)
                        .hide(mFindFragment)
                        .hide(mMeFragment)
                        .commit();
                break;
            case  R.id.menu_find:
                this.getSupportFragmentManager()
                        .beginTransaction()
                        .hide(mMainFragment)
                        .show(mFindFragment)
                        .hide(mMeFragment)
                        .commit();
                break;
            case  R.id.menu_me:
                this.getSupportFragmentManager()
                        .beginTransaction()
                        .hide(mMainFragment)
                        .hide(mFindFragment)
                        .show(mMeFragment)
                        .commit();
                break;


        }
    }
}